package com.dt.platform.generator.module.oa;

import com.dt.platform.constants.db.OaTables;
import com.dt.platform.constants.enums.common.StatusEnableEnum;
import com.dt.platform.domain.oa.ProjectPhase;
import com.dt.platform.domain.oa.meta.ProjectMeta;
import com.dt.platform.domain.oa.meta.ProjectPhaseMeta;
import com.dt.platform.domain.oa.meta.ProjectTaskMeta;
import com.dt.platform.domain.oa.meta.ProjectTaskRcdMeta;
import com.dt.platform.generator.config.Config;
import com.dt.platform.oa.page.ProjectPhasePageController;
import com.dt.platform.proxy.oa.ProjectPhaseServiceProxy;
import com.github.foxnic.generator.builder.view.config.DatePickerType;
import com.github.foxnic.generator.config.WriteMode;
import org.github.foxnic.web.domain.hrm.Employee;
import org.github.foxnic.web.domain.system.DictItem;
import org.github.foxnic.web.domain.system.meta.DictItemMeta;
import org.github.foxnic.web.proxy.system.DictItemServiceProxy;

public class AProjectPhaseGtr extends BaseCodeGenerator {


    public AProjectPhaseGtr() {
        super(OaTables.OA_PROJECT_PHASE.$TABLE,"705020984087805957");
    }

    public void generateCode() throws Exception {
        System.out.println(this.getClass().getName());

        cfg.view().field(OaTables.OA_PROJECT_PHASE.ID).basic().hidden(true);
        cfg.view().field(OaTables.OA_PROJECT_PHASE.CT).search().fuzzySearch();


        cfg.getPoClassFile().addSimpleProperty(DictItem.class,"phaseTplDict","phaseTplDict","phaseTplDict");

        cfg.getPoClassFile().addSimpleProperty(Employee.class,"leader","leader","leader");
        cfg.getPoClassFile().addSimpleProperty(String.class,"dateRange","dateRange","dateRange");

        cfg.getPoClassFile().addListProperty(Employee.class,"partUserList","partUserList","partUserList");
        cfg.getPoClassFile().addListProperty(String.class,"partUserStrList","partUserStrList","partUserStrList");





        cfg.view().search().inputLayout(
                new Object[]{
                        OaTables.OA_PROJECT_PHASE.SDATE,
                }
        );
        cfg.view().search().disable();



        cfg.view().field(OaTables.OA_PROJECT_PHASE.TPL)
                .form().selectBox().queryApi(DictItemServiceProxy.QUERY_PAGED_LIST+"?dictCode=oa_project_phase_tpl")
                .defaultIndex(1).paging(true).filter(true).toolbar(true)
                .valueField(DictItemMeta.CODE).
                textField(DictItemMeta.LABEL).
                fillWith(ProjectPhaseMeta.PHASE_TPL_DICT).muliti(false);

        cfg.view().field(OaTables.OA_PROJECT_PHASE.TPL_STATUS)
               .form().radioBox().enumType(StatusEnableEnum.class).defaultValue("disable");

        cfg.view().field(ProjectPhaseMeta.PART_USER_STR_LIST).basic().label("阶段成员").form()
                .button().chooseEmployee(false);


        cfg.view().field(OaTables.OA_PROJECT_PHASE.SDATE).form().validate().required().form().dateInput().defaultNow().format("yyyy-MM-dd").type(DatePickerType.date).search().range();
        cfg.view().field(OaTables.OA_PROJECT_PHASE.EDATE).form().validate().required().form().dateInput().defaultNow().format("yyyy-MM-dd").type(DatePickerType.date).search().range();


        cfg.view().field(OaTables.OA_PROJECT_PHASE.LEADER_ID).table().fillBy("leader","name");
        cfg.view().field(OaTables.OA_PROJECT_PHASE.LEADER_ID).form().validate().required().form()
                .button().chooseEmployee(true);


        cfg.view().field(OaTables.OA_PROJECT_PHASE.UPDATE_BY).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT_PHASE.UPDATE_BY).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT_PHASE.CREATE_BY).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT_PHASE.CREATE_TIME).table().disable(true);

        cfg.view().field(OaTables.OA_PROJECT_PHASE.TPL).table().disable(true);

        cfg.view().field(OaTables.OA_PROJECT_PHASE.TPL_STATUS).table().disable(true);
        cfg.view().list().disableBatchDelete();
        cfg.view().search().labelWidth(1,Config.searchLabelWidth);
        cfg.view().search().labelWidth(2,Config.searchLabelWidth);
        cfg.view().search().labelWidth(3,Config.searchLabelWidth);
        cfg.view().search().labelWidth(4,Config.searchLabelWidth);
        cfg.view().search().inputWidth(Config.searchInputWidth);

        cfg.view().field(ProjectPhaseMeta.PART_USER_LIST).table().disable(true);

        cfg.view().field(OaTables.OA_PROJECT_PHASE.NAME).form().validate().required();
        cfg.view().field(OaTables.OA_PROJECT_PHASE.CT).form().textArea().height(120);

        cfg.view().field(ProjectPhaseMeta.DATE_RANGE).basic().label("阶段周期");

        cfg.view().list().columnLayout(OaTables.OA_PROJECT_PHASE.RK,OaTables.OA_PROJECT_PHASE.NAME,OaTables.OA_PROJECT_PHASE.LEADER_ID,ProjectPhaseMeta.DATE_RANGE,ProjectPhaseMeta.PART_USER_STR_LIST);

        cfg.view().formWindow().bottomSpace(100);
        cfg.view().formWindow().width(Config.baseFormWidth);



        cfg.view().form().addGroup("阶段模版",
                new Object[] {
                        OaTables.OA_PROJECT_PHASE.TPL_STATUS
                }
//                ,
//                new Object[] {
//                        OaTables.OA_PROJECT_PHASE.TPL,
//                }
        );


        cfg.view().form().addGroup("阶段信息",
                new Object[] {
                        OaTables.OA_PROJECT_PHASE.NAME,
                        OaTables.OA_PROJECT_PHASE.LEADER_ID,
                        ProjectPhaseMeta.PART_USER_STR_LIST
                },
                new Object[] {
                        OaTables.OA_PROJECT_PHASE.SDATE,
                        OaTables.OA_PROJECT_PHASE.EDATE,
                }
        );
        cfg.view().form().addGroup(null,
                new Object[] {
                        OaTables.OA_PROJECT_PHASE.CT,
                }
        );

        cfg.view().field(OaTables.OA_PROJECT_PHASE.UPDATE_BY).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT_PHASE.UPDATE_TIME).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT_PHASE.CREATE_BY).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT_PHASE.PROJECT_ID).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT_PHASE.EDATE).table().disable(true);
        cfg.view().field(OaTables.OA_PROJECT_PHASE.SDATE).table().disable(true);

        cfg.view().list().operationColumn().addActionButton("上移","actionUp","action-up");
        cfg.view().list().operationColumn().addActionButton("下移","actionDown","actionDown");

        cfg.view().list().addJsVariable("PAGE_TYPE","[[${pageType}]]","pageType");
        cfg.view().list().addJsVariable("PROJECT_ID","[[${projectId}]]","projectId");
        cfg.view().form().addJsVariable("PROJECT_ID","[[${projectId}]]","projectId");

        cfg.view().form().addJsVariable("CUR_EMP_ID","[[${curEmpId}]]","curEmpId");
        cfg.view().form().addJsVariable("CUR_USER_NAME","[[${curUserName}]]","curUserName");

        //文件生成覆盖模式
        cfg.overrides()
                .setServiceIntfAnfImpl(WriteMode.IGNORE) //服务与接口
                .setControllerAndAgent(WriteMode.IGNORE) //Rest
                .setPageController(WriteMode.IGNORE) //页面控制器
                .setFormPage(WriteMode.COVER_EXISTS_FILE) //表单HTML页
                .setListPage(WriteMode.COVER_EXISTS_FILE)
                .setExtendJsFile(WriteMode.IGNORE); //列表HTML页

        cfg.buildAll();
    }

    public static void main(String[] args) throws Exception {
        AProjectPhaseGtr g=new AProjectPhaseGtr();
        //生成代码
        g.generateCode();

        //移除之前生成的菜单，视情况执行
//        g.removeByBatchId("471622036347682816");
        //生成菜单
     //   g.generateMenu(ProjectPhaseServiceProxy.class, ProjectPhasePageController.class);
    }

}
